#include "header.h"

/* -------------------------------------------------------------------------- */
void QDerv(struct node* p,double** var_old){
/* -------------------------------------------------------------------------- */
int i;
void q_derivative1(int,struct node*,double**,double*,double*,double*);
for(i=0;i<no_grid_points;i++)
	q_derivative1(i,p,var_old,p[i].qx,p[i].qy,p[i].qz);
}

/* -------------------------------------------------------------------------- */
/* Finds the derivatives using full stencil. Derivative is required at neigh  */
void q_derivative1(int neigh,struct node* p,double** var_old,double* qx,
                   double* qy,double* qz){
/* -------------------------------------------------------------------------- */
int i,j,k,neigh1,tolimit;
double dq;


for(k=0;k<5;k++) qx[k] = qy[k] = qz[k] = 0.0;

if(p[neigh].point_type==CONST) return;


for(j=0;j<p[neigh].total_conn;j++){

	neigh1 = p[neigh].Conn[j];
	for(k=0;k<5;k++){
		dq     = var_old[neigh1][k] - var_old[neigh][k];
		qx[k] += p[neigh].X[j]*dq;
		qy[k] += p[neigh].Y[j]*dq;
		qz[k] += p[neigh].Z[j]*dq;
		}
	}


}
/* -------------------------------------------------------------------------- */
